from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response

# Create your views here.
from user import serializers,models
import re
class User(viewsets.ModelViewSet):
    queryset = models.User.objects.all()
    serializer_class = serializers.UserSerializer
    @action(detail=False,methods=['POST'])
    def qwe(self,request):
        username = request.data.get('username')
        password = request.data.get('password')
        if re.match(r'^1[3-9]\d{9}$',username):
            user = models.User.objects.filter(username=username, password=password)
            if user:
                return Response({'code': 200, 'msg': '登录成功'})
            else:
                return Response({'code': 400, 'msg': '用户名或密码错误'})
        else:
            return Response({'code': 400, 'msg': '手机号格式错误'})




